<template>
  <div class="cute-journal">
    <!-- 背景装饰元素 -->
    <div class="background-decorations">
      <div class="star star-1">⭐</div>
      <div class="star star-2">✨</div>
      <div class="star star-3">💫</div>
      <div class="heart heart-1">💗</div>
      <div class="heart heart-2">💕</div>
    </div>

    <div class="entries-masonry">
      <div
        v-for="(entry, index) in entries"
        :key="entry.id"
        class="entry-card"
        :class="[`card-color-${(index % 5) + 1}`, `tilt-${(index % 3)}`]"
        :style="{ animationDelay: `${index * 0.15}s` }"
      >
        <!-- 胶带装饰 -->
        <div class="washi-tape" :class="`tape-${(index % 4) + 1}`"></div>

        <!-- 别针装饰 -->
        <div class="pin" :class="`pin-color-${(index % 3) + 1}`">📌</div>

        <!-- 日期卡片 -->
        <div class="date-card">
          <div class="date-main">{{ formatDayMonth(entry.date) }}</div>
          <div class="date-year">{{ formatYear(entry.date) }}</div>
        </div>

        <!-- 心情和天气贴纸 -->
        <div class="stickers">
          <div v-if="entry.weather" class="sticker weather-sticker">
            <span class="sticker-emoji">{{ getWeatherEmoji(entry.weather) }}</span>
            <span class="sticker-text">{{ getWeatherText(entry.weather) }}</span>
          </div>
          <div v-if="entry.mood" class="sticker mood-sticker" :class="`mood-${entry.mood}`">
            <span class="sticker-emoji">{{ getMoodEmoji(entry.mood) }}</span>
            <span class="sticker-text">{{ getMoodText(entry.mood) }}</span>
          </div>
        </div>

        <!-- 标题 -->
        <h3 v-if="entry.title" class="entry-title">
          <span class="title-highlight">{{ entry.title }}</span>
        </h3>

        <!-- 内容 -->
        <div class="entry-content">
          <p>{{ entry.content }}</p>
        </div>

        <!-- 标签（可爱贴纸样式） -->
        <div v-if="entry.tags && entry.tags.length" class="cute-tags">
          <span
            v-for="(tag, tagIndex) in entry.tags"
            :key="tag"
            class="cute-tag"
            :class="`tag-style-${(tagIndex % 4) + 1}`"
          >
            {{ tag }}
          </span>
        </div>

        <!-- 装饰性元素 -->
        <div class="decorative-elements">
          <span class="deco-element">{{ getRandomDeco(index) }}</span>
        </div>

        <!-- 时间标签 -->
        <div class="time-label">
          ⏰ {{ formatTime(entry.createdAt) }}
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import type { JournalEntry } from '../types'

interface Props {
  entries: JournalEntry[]
}

defineProps<Props>()

const formatDayMonth = (dateStr: string) => {
  const date = new Date(dateStr)
  return `${date.getMonth() + 1}/${date.getDate()}`
}

const formatYear = (dateStr: string) => {
  const date = new Date(dateStr)
  return date.getFullYear()
}

const formatTime = (dateStr: string) => {
  const date = new Date(dateStr)
  return date.toLocaleTimeString('zh-CN', {
    hour: '2-digit',
    minute: '2-digit'
  })
}

const getWeatherEmoji = (weather: string) => {
  const weatherMap: Record<string, string> = {
    sunny: '☀️',
    cloudy: '☁️',
    rainy: '🌧️',
    snowy: '❄️'
  }
  return weatherMap[weather] || '🌈'
}

const getWeatherText = (weather: string) => {
  const weatherTextMap: Record<string, string> = {
    sunny: '晴天',
    cloudy: '多云',
    rainy: '雨天',
    snowy: '下雪'
  }
  return weatherTextMap[weather] || weather
}

const getMoodEmoji = (mood: string) => {
  const moodMap: Record<string, string> = {
    happy: '😊',
    sad: '😢',
    neutral: '😐',
    excited: '🤩',
    tired: '😴'
  }
  return moodMap[mood] || '😊'
}

const getMoodText = (mood: string) => {
  const moodTextMap: Record<string, string> = {
    happy: '开心',
    sad: '难过',
    neutral: '平静',
    excited: '兴奋',
    tired: '疲惫'
  }
  return moodTextMap[mood] || mood
}

const getRandomDeco = (index: number) => {
  const decos = ['🌸', '🌺', '🌼', '🌻', '🌷', '🦋', '🐝', '🍀']
  return decos[index % decos.length]
}
</script>

<style scoped>
.cute-journal {
  min-height: 100vh;
  padding: 30px 20px;
  background: linear-gradient(135deg, #fff5f7 0%, #ffe8f0 50%, #fff0f5 100%);
  position: relative;
  overflow: hidden;
}

/* 背景装饰 */
.background-decorations {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 0;
}

.star, .heart {
  position: absolute;
  font-size: 32px;
  animation: float 6s ease-in-out infinite;
  opacity: 0.3;
}

.star-1 { top: 10%; left: 10%; animation-delay: 0s; }
.star-2 { top: 20%; right: 15%; animation-delay: 2s; }
.star-3 { bottom: 15%; left: 20%; animation-delay: 4s; }
.heart-1 { top: 60%; right: 10%; animation-delay: 1s; }
.heart-2 { bottom: 30%; right: 25%; animation-delay: 3s; }

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(10deg); }
}

/* 瀑布流布局 */
.entries-masonry {
  position: relative;
  z-index: 1;
  columns: 3;
  column-gap: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

@media (max-width: 1024px) {
  .entries-masonry { columns: 2; }
}

@media (max-width: 640px) {
  .entries-masonry { columns: 1; }
}

.entry-card {
  break-inside: avoid;
  margin-bottom: 24px;
  padding: 24px;
  border-radius: 20px;
  position: relative;
  box-shadow: 0 6px 20px rgba(255, 105, 180, 0.2);
  animation: popIn 0.5s ease-out backwards;
  overflow: visible;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.8) translateY(30px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* 不同颜色的卡片 */
.card-color-1 { background: linear-gradient(135deg, #ffeef8 0%, #ffe0f0 100%); }
.card-color-2 { background: linear-gradient(135deg, #fff4e6 0%, #ffe8cc 100%); }
.card-color-3 { background: linear-gradient(135deg, #e6f7ff 0%, #d1f0ff 100%); }
.card-color-4 { background: linear-gradient(135deg, #f0fff4 0%, #dffde8 100%); }
.card-color-5 { background: linear-gradient(135deg, #fff0f6 0%, #ffe6f0 100%); }

/* 轻微倾斜效果 */
.tilt-0 { transform: rotate(-1deg); }
.tilt-1 { transform: rotate(1deg); }
.tilt-2 { transform: rotate(-0.5deg); }

.entry-card:hover {
  transform: rotate(0deg) translateY(-4px) !important;
  box-shadow: 0 12px 30px rgba(255, 105, 180, 0.3);
  transition: all 0.3s ease;
}

/* 胶带装饰 */
.washi-tape {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 24px;
  border-radius: 2px;
  opacity: 0.7;
}

.tape-1 {
  background: repeating-linear-gradient(
    45deg,
    #ff9a9e,
    #ff9a9e 10px,
    #fad0c4 10px,
    #fad0c4 20px
  );
}

.tape-2 {
  background: repeating-linear-gradient(
    45deg,
    #a8edea,
    #a8edea 10px,
    #fed6e3 10px,
    #fed6e3 20px
  );
}

.tape-3 {
  background: repeating-linear-gradient(
    45deg,
    #ffd3a5,
    #ffd3a5 10px,
    #fd6585 10px,
    #fd6585 20px
  );
}

.tape-4 {
  background: repeating-linear-gradient(
    45deg,
    #c1fba4,
    #c1fba4 10px,
    #f7e98e 10px,
    #f7e98e 20px
  );
}

/* 别针 */
.pin {
  position: absolute;
  top: -8px;
  right: 30px;
  font-size: 28px;
  transform: rotate(45deg);
  filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.2));
}

.pin-color-1 { filter: hue-rotate(0deg) drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.2)); }
.pin-color-2 { filter: hue-rotate(120deg) drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.2)); }
.pin-color-3 { filter: hue-rotate(240deg) drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.2)); }

/* 日期卡片 */
.date-card {
  display: inline-block;
  background: white;
  padding: 12px 20px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(255, 105, 180, 0.2);
  margin-bottom: 16px;
  border: 3px solid #ffb6c1;
  text-align: center;
}

.date-main {
  font-size: 24px;
  font-weight: 700;
  color: #ff69b4;
}

.date-year {
  font-size: 12px;
  color: #ff8fab;
  margin-top: 4px;
}

/* 贴纸 */
.stickers {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.sticker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  background: white;
  border: 2px solid;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transform: rotate(-3deg);
}

.weather-sticker {
  border-color: #ffd700;
  color: #ff8c00;
}

.mood-sticker {
  transform: rotate(3deg);
}

.mood-sticker.mood-happy { border-color: #ffd93d; color: #ff8c00; }
.mood-sticker.mood-sad { border-color: #6bcfff; color: #1e90ff; }
.mood-sticker.mood-neutral { border-color: #d3d3d3; color: #696969; }
.mood-sticker.mood-excited { border-color: #ff69b4; color: #ff1493; }
.mood-sticker.mood-tired { border-color: #dda0dd; color: #9370db; }

.sticker-emoji {
  font-size: 18px;
}

/* 标题 */
.entry-title {
  font-size: 22px;
  font-weight: 700;
  color: #ff69b4;
  margin: 0 0 16px 0;
  line-height: 1.4;
}

.title-highlight {
  background: linear-gradient(to right, #ffd1dc, #ffb6c1);
  padding: 4px 12px;
  border-radius: 8px;
  display: inline-block;
  box-shadow: 0 2px 6px rgba(255, 182, 193, 0.4);
}

/* 内容 */
.entry-content {
  margin-bottom: 16px;
}

.entry-content p {
  font-size: 15px;
  line-height: 1.8;
  color: #555;
  margin: 0;
}

/* 可爱标签 */
.cute-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.cute-tag {
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  position: relative;
}

.tag-style-1 {
  background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
  color: #d63031;
}

.tag-style-2 {
  background: linear-gradient(135deg, #a29bfe 0%, #6c5ce7 100%);
  color: white;
}

.tag-style-3 {
  background: linear-gradient(135deg, #fd79a8 0%, #e84393 100%);
  color: white;
}

.tag-style-4 {
  background: linear-gradient(135deg, #55efc4 0%, #00b894 100%);
  color: white;
}

/* 装饰元素 */
.decorative-elements {
  position: absolute;
  bottom: 15px;
  right: 15px;
}

.deco-element {
  font-size: 32px;
  opacity: 0.3;
  display: inline-block;
  animation: rotate 4s linear infinite;
}

@keyframes rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* 时间标签 */
.time-label {
  font-size: 12px;
  color: #999;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 2px dashed #ffb6c1;
}
</style>
